package com.content.scaffold.common.aspect;

import com.content.scaffold.common.utils.SensitiveFieldEncryptor;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @author xiaojl
 */
@Aspect
@Component
public class EncryptParamAspect {

    @Before("@annotation(com.content.scaffold.common.annotation.EncryptParam)")
    public void beforeEncryptParam(JoinPoint joinPoint) {
        for (Object arg : joinPoint.getArgs()) {
            if (arg == null) {
                continue;
            }
            // 只处理对象类型参数（非原始类型）
            if (!(arg instanceof String) && !(arg.getClass().isPrimitive())) {
                SensitiveFieldEncryptor.encryptSensitiveFields(arg);
            }
        }
    }
}
